import request from "../utils/request";
import {baseServerUrl} from "../utils/Constant";
import {stringify} from "qs";

export async function linePage(params) {
  return request(`${baseServerUrl}/tms/tms-line/page?${stringify(params)}`, {
    method: 'GET'
  })
}

export async function carTypePage(params) {
  return request(`${baseServerUrl}/tms/tms-car-type/page?${stringify(params)}`, {
    method: 'GET'
  })
}

export async function pricePage(params) {
  return request(`${baseServerUrl}/tms/tms-line/price-page?${stringify(params)}`, {
    method: 'GET'
  })
}

export async function insertOrUpdateLine(params) {
  const { id } = params;
  let method = 'PUT';
  if(!id){
    method = 'POST';
    delete params['id']
  }
  return request(`${baseServerUrl}/tms/tms-line`, {
    method: method,
    body: {
      ...params,
    }
  })
}

export async function insertOrUpdateCarType(params) {
  const { id } = params;
  let method = 'PUT';
  if(!id){
    method = 'POST';
    delete params['id']
  }
  return request(`${baseServerUrl}/tms/tms-car-type`, {
    method: method,
    body: {
      ...params,
    }
  })
}

export async function insertOrUpdatePrice(params) {
  const { id } = params;
  let method = 'PUT';
  if(!id){
    method = 'POST';
    delete params['id']
  }
  return request(`${baseServerUrl}/tms/tms-line/price`, {
    method: method,
    body: {
      ...params,
    }
  })
}

export async function delLine(params) {
  return request(`${baseServerUrl}/tms/tms-line`, {
    method: 'DELETE',
    body: params
  })
}

export async function delCarType(params) {
  return request(`${baseServerUrl}/tms/tms-car-type`, {
    method: 'DELETE',
    body: params
  })
}

export async function lineOptions(params) {
  return request(`${baseServerUrl}/tms/tms-line/select-list?${stringify(params)}`, {
    method: 'GET'
  })
}

export async function carTypeOptions(params) {
  return request(`${baseServerUrl}/tms/tms-car-type/select-list?${stringify(params)}`, {
    method: 'GET'
  })
}

export async function hasPrice() {
  return request(`${baseServerUrl}/tms/tms-line/hasPrice`, {
    method: 'GET'
  })
}
